package com.stormrage.edu.dao.student.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.student.StuInfoDao;
import com.stormrage.entity.student.StuInfo;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: StuInfoDaoImpl.java
 * @Package com.stormrage.edu.dao.student.impl
 * @Description: 学员账户信息 Dao
 * @author www.stormragetech.com
 * @date 2016年4月15日
 * @version V1.0
 */
@Repository
public class StuInfoDaoImpl extends MysBaseDao implements StuInfoDao {

	private static final Logger logger = LoggerFactory.getLogger(StuInfoDaoImpl.class);

	@Override
	public Integer create(final StuInfo arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 StuAcctDao 】-【 Create 】-【 STARTED 】");

		final String query = "INSERT INTO stu_info (acct_id, real_name, id_card, image, depart, phone, email, address, zipcode) VALUES"
				+ " (:acctId, :realName, :idCard, :image, :depart, :phone, :email, :address, :zipcode)";
		logger.debug(" 数据库执行语句为 " + query);

		Integer index = create(query, arg0);

		logger.debug(" 【 Dao 】-【 StuAcctDao 】-【 Create 】-【 COMPLETED 】");
		return index;

	}

	@Override
	public void update(final StuInfo arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 StuAcctDao 】-【 Update 】-【 STARTED 】");

		final String query = "UPDATE stu_info SET real_name = :realName, id_card = :idCard, depart = :depart,"
				+ " phone = :phone, email = :email, address = :address, zipcode = :zipcode WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, arg0);

		logger.debug(" 【 Dao 】-【 StuAcctDao 】-【 Update 】-【 COMPLETED 】");

	}

	@Override
	public void updateImage(final StuInfo arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 StuAcctDao 】-【 UpdateImage 】-【 STARTED 】");

		final String query = "UPDATE stu_info SET image = :image WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, arg0);

		logger.debug(" 【 Dao 】-【 StuAcctDao 】-【 UpdateImage 】-【 COMPLETED 】");

	}

	@Override
	public StuInfo queryByAcct(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 StuAcctDao 】-【 QueryById 】-【 STARTED 】");

		final String query = "SELECT * FROM stu_info WHERE acct_id = :acctId";
		logger.debug(" 数据库执行语句为 " + query);

		StuInfo entity = queryObject(query, StuInfo.class, map);

		logger.debug(" 【 Dao 】-【 StuAcctDao 】-【 QueryById 】-【 COMPLETED 】");
		return entity;

	}

}
